package net.chathu.airgw.packets.chat 
{
	import net.chathu.airgw.model.JoinedRoomInfo;
	import net.chathu.airgw.model.Room;
	import net.chathu.airgw.packets.gw.serverpackets.TopicPacket;
	/**
	 * ...
	 * @author ze
	 */
	public class IChgRooms extends ChatPacket 
	{
		
		public function IChgRooms() 
		{
			
		}
		
		override public function execute():void
		{

			var roomId:int = parseInt(data[2]);
			var pos:int = data[4].indexOf(":");
			
			var usernum:int = parseInt(data[4].substring(0,pos));
			var modnum:int = parseInt(data[4].substring(pos + 1));
			
			
			
			var room:Room = sessionData.chatData.rooms.getRoom(roomId);
			
			if (room)
			{
				room.userNum = usernum;
				if (room.modNum != modnum)
				{
					room.modNum = modnum;
					
					var roomInfo:JoinedRoomInfo = sessionData.chatData.getJoinedRoomInfo(roomId);
					if (roomInfo) {
						//ha bennt van az az adott szobaban:
						sendToClient(new TopicPacket(sessionData.nick, room.name, room.topic));
					}
				}
				
			} else {
				trace("Missing room, roomId: " + roomId + "(IChgRooms)");
			}
			
		}
		
	}

}